<template>
    <div class="tab">
        <van-tabs v-model="active" @click="change">
            <van-tab
                v-for="(item, i) in listtop"
                :key="i"
                :title="item.title"
                :name="item.tab"
            ></van-tab>
        </van-tabs>
        <list :list="list"></list>
    </div>
</template>

<script>
import list from "@/components/list";
export default {
    components: {
        list,
    },
    data() {
        return {
            active: localStorage.getItem("tab") || "whole",
            listtop: [
                {
                    title: "全部",
                    tab: "ask",
                },
                {
                    title: "精华",
                    tab: "share",
                },
                {
                    title: "分享",
                    tab: "ask",
                },
                {
                    title: "问答",
                    tab: "share",
                },
                {
                    title: "招聘",
                    tab: "ask",
                },
                {
                    title: "客户端测试",
                    tab: "share",
                },
            ],
            list: [],
        };
    },
    mounted() {
        this.change();
    },
    methods: {
        change() {
            localStorage.setItem("tab", this.active);
            this.list = [];
            this.$axios.get("/list.json").then((res) => {
                console.log(res);
                res.data.data.forEach((item) => {
                    // console.log(item);
                    if (item.tab == this.active) {
                        this.list.push(item);
                    }
                });
            });
        },
    },
};
</script>

<style lang="scss"></style>
